﻿package mortal.game.view.rebate.openServerSevenDay.item
{
    import com.mui.controls.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;

    public class OpenServerSevenDayDayTabPanel extends GSprite
    {
        private var _select:OpenServerSevenTabCell;
        protected var _tabList:CellsGridSprite;

        public function OpenServerSevenDayDayTabPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tabList = UIFactory.getUICompoment(CellsGridSprite);
            this._tabList.colNum = 100;
            this._tabList.vCellWid = 98;
            this._tabList.hCellWid = 46;
            this._tabList.genCellFun = UIFactory.getUICompoment;
            this._tabList.x = 0;
            this._tabList.y = 0;
            this.addChild(this._tabList);
            this.configEventListener(MouseEvent.CLICK, this.onSelectHd);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._tabList.dispose(param1);
            this._tabList = null;
            this._select = null;
            return;
        }// end function

        public function initTabs() : void
        {
            var _loc_1:* = OpenServerSevenDayUtil.getSevenDayTabData();
            Cache.instance.openServerSevenDay.sevenDayTabArr = _loc_1[0];
            Cache.instance.openServerSevenDay.sevenDayRangeTabArr = _loc_1[1];
            this.setData(_loc_1[0]);
            return;
        }// end function

        public function getDayNumByIndex(param1:int) : int
        {
            var _loc_2:* = Cache.instance.openServerSevenDay.sevenDayTabArr;
            return int(_loc_2[param1].dayNum);
        }// end function

        public function setData(param1:Array) : void
        {
            var _loc_3:* = undefined;
            var _loc_4:OpenServerSevenTabCell = null;
            if (param1 == null)
            {
                return;
            }
            this._tabList.genCells(param1.length, OpenServerSevenTabCell);
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = param1[_loc_2];
                _loc_4 = this._tabList.cellArr[_loc_2] as OpenServerSevenTabCell;
                if (_loc_4)
                {
                    _loc_4.setData(_loc_3);
                }
                _loc_2++;
            }
            return;
        }// end function

        public function selectIndex(param1:int) : void
        {
            var _loc_2:* = undefined;
            if (this._tabList == null)
            {
                return;
            }
            _loc_2 = this._tabList.cellArr[param1];
            if (_loc_2 == null)
            {
                return;
            }
            if (this._select != null)
            {
                this._select.isSelect = false;
            }
            this._select = _loc_2;
            this._select.isSelect = true;
            return;
        }// end function

        public function onSelectHd(event:MouseEvent) : void
        {
            var _loc_2:GLoadingButton = null;
            var _loc_3:int = 0;
            var _loc_4:* = undefined;
            if (event == null)
            {
                _loc_3 = 0;
                _loc_4 = this._tabList.cellArr[_loc_3];
                if (this._select == _loc_4)
                {
                    return;
                }
                if (this._select != null)
                {
                    this._select.isSelect = false;
                }
                this._select = _loc_4;
                this._select.isSelect = true;
            }
            else
            {
                if (event.target is OpenServerSevenTabCell)
                {
                    _loc_4 = event.target;
                }
                else
                {
                    _loc_2 = event.target as GLoadingButton;
                    _loc_4 = _loc_2.parent;
                }
                if (this._select == _loc_4)
                {
                    return;
                }
                if (_loc_4 == null || this._tabList == null)
                {
                    return;
                }
                _loc_3 = this._tabList.cellArr.indexOf(_loc_4);
                if (this._select != null)
                {
                    this._select.isSelect = false;
                }
                if (_loc_3 != -1)
                {
                    this._select = _loc_4;
                    this._select.isSelect = true;
                }
            }
            this.dispatchEvent(new DataEvent(EventName.RebateTabSelect, _loc_3));
            return;
        }// end function

    }
}
